home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / wsc4c10.zip / SELFTEST.C < prev    next >
Text File  |  1996-09-08  |  5KB  |  213 lines

  1. /*
  2. **                    --- selftest.c ---
  3. */
  4.  
  5. #define USECOMM
  6.  
  7. #include "windows.h"
  8. #include "selftest.h"
  9. #include "message.h"
  10. #include "wsc.h"
  11. #include "ascii.h"
  12. #include "paint.h"
  13. #include "line.h"
  14. #include "menu.h"
  15. #include "about.h"
  16. #include "runtest.h"
  17. #include "wscerror.h"
  18.  
  19. /* public globals */
  20.  
  21. HWND hMainWnd;            /* main window handle */
  22. HWND hInfoWnd;            /* popup handle */
  23. HANDLE hInstance;         /* program instance */
  24. int OnLineFlag = FALSE;   /* TRUE: online */
  25. int FatalFlag = FALSE;    /* TRUE: fatal error */
  26. char Temp[1024];
  27.  
  28. /* private globals */
  29.  
  30. static int WinWidth = 8 * NCOLS;
  31. static int WinHeight = 12 * NROWS + 48;
  32. static int ThePort = COM1;
  33.  
  34. /* miscellaneous functions */
  35.  
  36. void ErrorCheck(int);
  37. void ErrorMessage(char *);
  38. void SetTitle(void);
  39.  
  40. int PASCAL WinMain(HANDLE hInst,HANDLE hPrevInstance,
  41.                    LPSTR lpCmdLine,int nCmdShow)
  42. {WNDCLASS  wc;
  43.  MSG msg;
  44.  BOOL Result;
  45.  if(!hPrevInstance)
  46.    {/* register main window class */
  47.     wc.style = CS_HREDRAW | CS_VREDRAW;
  48.     wc.lpfnWndProc = MainWndProc;
  49.     wc.cbClsExtra = 0;
  50.     wc.cbWndExtra = 0;
  51.     wc.hInstance = hInst;
  52.     wc.hIcon = LoadIcon(hInst, "SelftestIcon");
  53.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  54.     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  55.     wc.lpszMenuName =  "SelftestMenu";
  56.     wc.lpszClassName = "SelftestWClass";
  57.     Result = RegisterClass(&wc);
  58.     if(!Result) return FALSE;
  59.    }
  60.  
  61.  /* create main window */
  62.  hInstance = hInst;
  63.  hMainWnd = CreateWindow(
  64.         "SelftestWClass", "Selftest",       WS_OVERLAPPEDWINDOW,
  65.         CW_USEDEFAULT,    CW_USEDEFAULT,
  66.         WinWidth,         WinHeight,
  67.         NULL,             NULL,
  68.         hInstance,        NULL);
  69.  ShowWindow(hMainWnd, nCmdShow);
  70.  UpdateWindow(hMainWnd);
  71.  
  72.  /* window control loop */
  73.  
  74.  while(GetMessage(&msg,NULL,NULL,NULL))
  75.    {
  76.     TranslateMessage(&msg);
  77.     DispatchMessage(&msg);
  78.    }
  79.  return (msg.wParam);
  80. } /* end WinMain */
  81.  
  82. long FAR PASCAL MainWndProc(HWND hWindow,UINT message,WPARAM wParam,LPARAM lParam)
  83. {int  Code;
  84.  HDC  hDC;
  85.  PAINTSTRUCT ps;
  86.  static FARPROC lpProcAbout;
  87.  
  88.  hMainWnd = hWindow;
  89.  switch (message)
  90.     {case WM_COMMAND:
  91.          switch(wParam)
  92.            {case MSG_ABOUT:
  93.               DialogBox(hInstance,"AboutBox",hMainWnd,lpProcAbout);
  94.               break;
  95.  
  96.             case MSG_DEBUG:
  97.               break;
  98.  
  99.             case MSG_INSTRUCT:
  100.               DisplayLine("SELFTEST tests a single port for functionality.\n");
  101.               DisplayLine("The port must terminate with a loopback adapter.");
  102.               DisplayLine("See LOOPBACK.DOC for more info.\n");
  103.               break;
  104.  
  105.             case MSG_TEST:
  106.               Code = SioReset(ThePort,1024,1024);
  107.               if(Code<0)
  108.                 {SioError(Code,"SioReset");
  109.                  break;
  110.                 }
  111.               SioBaud(ThePort,19200);
  112.               RunTest(ThePort);
  113.               SioDone(ThePort);
  114.               break;
  115.  
  116.             case MSG_COM1:
  117.               UncheckTheMenu(MSG_COM1+ThePort);
  118.               ThePort = COM1;
  119.               CheckTheMenu(MSG_COM1);
  120.               SetTitle();
  121.               break;
  122.  
  123.             case MSG_COM2:
  124.               UncheckTheMenu(MSG_COM1+ThePort);
  125.               ThePort = COM2;
  126.               CheckTheMenu(MSG_COM2);
  127.               SetTitle();
  128.               break;
  129.  
  130.             case MSG_COM3:
  131.               UncheckTheMenu(MSG_COM1+ThePort);
  132.               ThePort = COM3;
  133.               CheckTheMenu(MSG_COM3);
  134.               SetTitle();
  135.               break;
  136.  
  137.             case MSG_COM4:
  138.               UncheckTheMenu(MSG_COM1+ThePort);
  139.               ThePort = COM4;
  140.               CheckTheMenu(MSG_COM4);
  141.               SetTitle();
  142.               break;
  143.  
  144.             case MSG_EXIT:
  145.               PostQuitMessage(0);
  146.               break;
  147.  
  148.             default:
  149.               return (DefWindowProc(hMainWnd, message, wParam, lParam));
  150.            }
  151.          break;
  152.  
  153.     case WM_CREATE:
  154.  
  155.       /* create AboutDlgProc() thunk */
  156.       lpProcAbout = MakeProcInstance(AboutDlgProc, hInstance);
  157.       /* initialize paint module */
  158.       InitPaint();
  159.       /* COM1 is default */
  160.       CheckTheMenu(MSG_COM1);
  161.       SetTitle();
  162.       break;
  163.  
  164. /*
  165.     case WM_CHAR:
  166.       SioPutc(ThePort, (char)wParam );
  167.       break;
  168. */
  169.  
  170.     case WM_SETFOCUS:
  171.       /* create client area caret */
  172.       CreateCaret(hMainWnd,NULL,3,10);
  173.       SetCaretPos(GetXposition(),GetYposition());
  174.       ShowCaret(hMainWnd);
  175.       ShowCaret(hMainWnd);
  176.       break;
  177.  
  178.     case WM_KILLFOCUS:
  179.       DestroyCaret();
  180.       break;
  181.  
  182.     case WM_PAINT:
  183.       HideCaret(hMainWnd);
  184.       hDC = BeginPaint(hMainWnd, &ps);
  185.       SetMapMode(hDC,MM_ANISOTROPIC);
  186.       SelectObject(hDC, GetStockObject(OEM_FIXED_FONT) );
  187.       PaintMain(hDC,&ps);
  188.       EndPaint(hMainWnd,&ps);
  189.       SetCaretPos(GetXposition(),GetYposition());
  190.       ShowCaret(hMainWnd);
  191.       break;
  192.  
  193.     case WM_DESTROY:
  194.       PostQuitMessage(0);
  195.       break;
  196.  
  197.     default:
  198.       return (DefWindowProc(hMainWnd, message, wParam, lParam));
  199.    }
  200.  return (NULL);
  201. } /* end MainWndProc */
  202.  
  203. void ErrorMessage(char *MsgPtr)
  204. {
  205.  MessageBox(hMainWnd,MsgPtr,"ERROR",MB_ICONEXCLAMATION | MB_OK);
  206. }
  207.  
  208. void SetTitle(void)
  209. {wsprintf((LPSTR)Temp,"SELFTEST: COM%d",1+ThePort);
  210.  SetWindowText(hMainWnd,Temp);
  211.  DrawMenuBar(hMainWnd);
  212. }
  213.